package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ProjectContractDetail;
import com.ruoyi.system.service.IProjectContractDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目合同内容Controller
 * 
 * @author ruoyi
 * @date 2024-07-22
 */
@RestController
@RequestMapping("/system/detail")
public class ProjectContractDetailController extends BaseController
{
    @Autowired
    private IProjectContractDetailService projectContractDetailService;

    /**
     * 查询项目合同内容列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ProjectContractDetail projectContractDetail)
    {
        startPage();
        List<ProjectContractDetail> list = projectContractDetailService.selectProjectContractDetailList(projectContractDetail);
        return getDataTable(list);
    }

    /**
     * 导出项目合同内容列表
     */
    @Log(title = "项目合同内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectContractDetail projectContractDetail)
    {
        List<ProjectContractDetail> list = projectContractDetailService.selectProjectContractDetailList(projectContractDetail);
        ExcelUtil<ProjectContractDetail> util = new ExcelUtil<ProjectContractDetail>(ProjectContractDetail.class);
        util.exportExcel(response, list, "项目合同内容数据");
    }

    /**
     * 获取项目合同内容详细信息
     */
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId)
    {
        return success(projectContractDetailService.selectProjectContractDetailByDetailId(detailId));
    }

    /**
     * 新增项目合同内容
     */
    @Log(title = "项目合同内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectContractDetail projectContractDetail)
    {
        return toAjax(projectContractDetailService.insertProjectContractDetail(projectContractDetail));
    }

    /**
     * 修改项目合同内容
     */
    @PreAuthorize("@ss.hasPermi('system:detail:edit')")
    @Log(title = "项目合同内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectContractDetail projectContractDetail)
    {
        return toAjax(projectContractDetailService.updateProjectContractDetail(projectContractDetail));
    }

    /**
     * 删除项目合同内容
     */
    @Log(title = "项目合同内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds)
    {
        return toAjax(projectContractDetailService.deleteProjectContractDetailByDetailIds(detailIds));
    }
}
